// Game.h: interface for the CGame class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_GAME_H__9DB43C9C_61F3_41C9_B4C6_44479D937297__INCLUDED_)
#define AFX_GAME_H__9DB43C9C_61F3_41C9_B4C6_44479D937297__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "robot.h"		//Predictor
#include "COMM.H"
//////////AutoPosition Define //////////////////////
#define		KICKOFF			0
#define		PENALITYKICK	1
#define		GOALIEKICK		2
#define		FREEKICK		3
#define		FREEBALL1		4
#define		FREEBALL2		5
#define		FREEBALL3		6
#define		FREEBALL4		7
#define     GAME			8

////////goalie define////////////////////////////////
#define		G_OFFSET		18.0
#define		G_ANGLE_BOUND	60
#define		G_BOUND			15.0
#define		G_LENGTH		40
#define		ATTACK			TRUE

////////ApproachBal////////////////////////////////
#define Center_R1		36
#define Center_R2		30
#define Shoot_L1		12
#define Shoot_L2		8

typedef struct
{
	double		X;		// position
	double		Y;		// position
} DPosition;				// Double point

typedef struct
{
	DPosition	position;		// position
	int			Angle;			// angle
	int			VelocityLeft;	// Left	 Wheel Velocity
	int			VelocityRight;	// Right Wheel Velocity
	BOOL		bFoundRobot;	// Found Robot Position flag
} RobotDPosition;				// Robot 

typedef struct
{
	DPosition	position;		// position
	BOOL		bFoundball;		// Found Ball Position flag
} BallDPosition;				// Ball information

class CGame  
{
public: //
	double Position_CONV_x;
	double Position_CONV_y;
	CString DisplayDebugData;	
	BOOL			m_bPositionAttackdir;	//Attack Direction
	int				RobotAutoPosition;		//AutoPosition Mode
	int				nSituationMode;			//
	double			tmp_angle[5];
	BYTE			command[10];			//Comport Communication	Array 
	RobotDPosition	MyRobot[5];				//Robot information
	RobotDPosition	OppRobot[5];			//OppRobot information
	BallDPosition	Ball;					//Ball position


	void	ComportTran(int portNum);
	void	ConvertVisionPoint(int *Robot,int *oppRobot,int *ball);
	void	SerialInit(void);
	void	AllRobotStop();
	void	SendCommand(BYTE *Data);
	void	AutoPosition(int AutoPositionMode,BOOL AttackOrDefense); //Mode is Position;direction Attack Or Defense
	void	My_Strategy();
	CPoint AvoidOBJ(int Mode,int whichrobot, double x, double y);


	POINT pGoal;
	POINT pTarget,pTarget_Left,pTarget_Right;
	POINT pShoot;
	double dx,dy;
	int Shoot_L,Center_R;
	CRect rGround,nGoal;
	POINT pCenter_Left,pCenter_Right;
	POINT pFront_Ball;
	
	double Goalangle_Top, Goalangle_Bottom;
	double Goalangle_Robot;
	double RtoBall_Angle;
	int RobottoGoalline_y;

	double deg_Ball,deg_Robot;
	double deg_r, deg_a;
	
	double distance_shoot;

	int approach_angle;

	BOOL bBallInWall_Top;
	BOOL bBallInWall_Bottom;
	BOOL bBallInWall_LeftTop;
	BOOL bBallInWall_LeftBottom;
	BOOL bBallInWall_RightTop;
	BOOL bBallInWall_RightBottom;

	CGame();
	virtual ~CGame();

private:
	void Attack2(int whichrobot);

	double Speed_Vparam;
	double Speed_Aparam;
	int Speed_Vmax;
	int Speed_Vmin;

	int Shoot(int whichrobot);
//didiet	int Shoot(int whichrobot, double x, double y);
	int Dribble(int whichrobot);
	int ApproachBall(int RobotID);
	BOOL AVOIDROBOT;
	int Home1,Home2,Home3,Home4;
	BOOL AttackAngleOfPosition(int whichrobot,double x,double y);
	BOOL Position(int whichrobot,POINT Target, double Vparam, double Aparam, int Max_Vel, int Min_Vel);
	void InitRole();
	void Gamealgorithm(int GameMode);
	void AngleOfPosition(int whichrobot,double x,double y);
	void Goalie(int whichrobot);
	
	////tambahan thesis : riki
	void spin(int whichrobot, bool arah);
	void CGame::AskingCondition();
	////end tambahan thesis : riki
	//////////////////////Goalie////////////////////////////

	double  hafeAngle(double Xp,double Yp);			//Half Angle Calculate
	bool	GoaliePosition(int whichrobot, double x, double y);

	////////////////basic Strategy///////////////////////
	void Attack();
	///////////////////////Attack Function/////////////
	void AKick(int whichrobot);
	double Field(double x,double y,double dest);

	///TAMBAHAN DIDIET
	int BallPassing(int me, int whichrobot);

	///END DIDIET

	////////////////////////////////////////////////////
	void Angle(int whichrobot, int desired_angle);				//Robot Angle Move function
	void angle2(int whichrobot,double x,double y);				//Desired Angle is Point
	bool DeffensePosition(int whichrobot, double x, double y);	//TO Position Function Not effect of robot Direction 

	void WhichRobotStop(int whichrobot);
	void Velocity(int whichrobot);
	long int		count2;			//Estimate Counter
	Predictor		preX;			//Estimate X point
	Predictor		preY;			//Estimate Y point
	CComm			m_CCom;			//Communication Class Valiable

};

#endif // !defined(AFX_GAME_H__9DB43C9C_61F3_41C9_B4C6_44479D937297__INCLUDED_)
